﻿Public MustInherit Class ItemPage
    Inherits BasePage

    Protected Overridable ReadOnly Property InsertionPermitted() As Boolean
        Get
            Return Roles.IsUserInRole("Manager") Or Roles.IsUserInRole("Member")
        End Get
    End Property

    Protected Function GetCurrentUserID() As ULong
        Return GetUserID(User.Identity.Name)
    End Function

    Protected Function GetUserID(ByVal userName As String) As ULong
        Dim gateway As New SiteUserGateway()
        Return gateway.FindByUserName(userName).Rows(0)("ID")
    End Function

    Protected Function GetPhotoNormalPath(ByVal fileName As String) As String
        Return PhotoUtils.GetNormalPath(fileName)
    End Function

    Protected Function GetPhotoNormalPath(ByVal photoID As ULong) As String
        Return GetPhotoNormalPath(GetPhotoFilenameByID(photoID))
    End Function

    Protected Function GetPhotoThumbPath(ByVal fileName As String) As String
        Return PhotoUtils.GetThumbPath(fileName)
    End Function

    Protected Function GetPhotoThumbPath(ByVal photoID As ULong) As String
        Return GetPhotoThumbPath(GetPhotoFilenameByID(photoID))
    End Function

    Private Function GetPhotoFilenameByID(ByVal photoID As ULong) As String
        Dim gateway As New PhotoGateway()
        Dim filename As String = gateway.FindByID(photoID).Rows(0)("ImagePath")
        Return filename
    End Function
End Class
